package driver

import (
	"github.com/gin-gonic/gin"
	v1 "golang-sgg-daijia/api/v1"
	"golang-sgg-daijia/internal/handler"
	"golang-sgg-daijia/internal/service"
	"net/http"
)

type OcrHandler struct {
	*handler.Handler
	ocrService service.OcrService
}

func NewOcrHandler(
	handler *handler.Handler,
	ocrService service.OcrService,
) *OcrHandler {
	return &OcrHandler{
		Handler:    handler,
		ocrService: ocrService,
	}
}

// UploadDriverLicenseOcr 身份证识别
func (h *OcrHandler) UploadDriverLicenseOcr(ctx *gin.Context) {
	file, err := ctx.FormFile("file")
	if err != nil {
		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, nil)
		return
	}
	idCardOCRVo, err := h.ocrService.IDCardOCR(ctx, file)
	if err != nil {
		v1.HandleError(ctx, http.StatusInternalServerError, v1.ErrInternalServerError, nil)
		return
	}
	v1.HandleSuccess(ctx, idCardOCRVo)
}

// DriverLicenseOcr 驾驶证识别
func (h *OcrHandler) DriverLicenseOcr(ctx *gin.Context) {
	file, err := ctx.FormFile("file")
	if err != nil {
		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, nil)
		return
	}
	driverLicenseOcrVo, err := h.ocrService.DriverLicenseOcr(ctx, file)
	if err != nil {
		v1.HandleError(ctx, http.StatusInternalServerError, v1.ErrInternalServerError, nil)
		return
	}
	v1.HandleSuccess(ctx, driverLicenseOcrVo)
}
